const Base = require('./base.js');

module.exports = class extends Base {
  indexAction() {
    return this.display();
  }

  async testAction() {
    const user=this.ctx.mongo("user");
    //console.log(user.tableName);
    const data=await user.select();
    this.assign("comment",data);
    await this.display("comment.html");
  }

  async commentAction() {
    const user=this.ctx.mongo("user");
    await user.where({goods: 0}).increment("coins", 10);
    this.redirect("/index/test");
  }

  async payAction(){
    const user=this.ctx.mongo("user");
    await user.decrement("coins", 1);
    this.redirect("/index/test");
  }

  async delAction(){
    const user=this.ctx.mongo("user");
    await user.delete();
    this.redirect("/index/test");
  }

  async getAction(){
    const user=this.ctx.mongo("user");
    const r=await user.increment("goods",1);
    this.redirect("/index/test");
  }

  async addAction(){
    const user=this.ctx.mongo("user");
    user.addMany([{goods:0,coins:0},{goods:0,coins:0}]);
    this.redirect("/index/test");
  }
};
